package com.ny.zmb.openapi.controller;

import com.alibaba.fastjson.JSONObject;
import com.ny.zmb.openapi.controller.entity.Result;
import com.ny.zmb.openapi.ysutil.YsHttpUtil;
import com.ny.zmb.openapi.ysutil.base.EYinShengBase;
import com.ny.zmb.openapi.ysutil.common.ServiceEnum;
import com.ny.zmb.openapi.ysutil.common.YsPayConstant;
import com.ny.zmb.openapi.ysutil.from.*;
import org.apache.logging.log4j.util.PerformanceSensitive;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 银盛配置
 */
@CrossOrigin
@RequestMapping("ys/config")
@RestController
public class YsConfigController extends EYinShengBase {

    @Resource
    private YsHttpUtil ysHttpUtil;

    /**
     * 微信实名认证
     *
     * @param command
     * @return
     */
    @PostMapping("wxAuthSubmitApply")
    public Result wxAuthSubmitApply(WxAuthMesSubmitRequestCommand command) {
        try {
            if (null == command) {
                return Result.fail("参数不能为空");
            }
            JSONObject send = ysHttpUtil.send(ServiceEnum.WX_AuthSubmitApply, YsPayConstant.ENV_PRD,
                    MERCHANT_PRX, MERCHANT_PRX_PWD, ServiceEnum.WX_AuthSubmitApply.getApiName(), command);
            JSONObject result = send.getJSONObject("bizResponseJson");
            return Result.ok(result);
        } catch (Exception var) {
            return Result.fail(var.getMessage());
        }
    }

    /**
     * 微信查询申请单状态
     *
     * @param command
     * @return
     */
    @GetMapping("wxAuthQueryByApplyNo")
    public Result wxAuthQueryByApplyNo(WxAuthQueryByApplyNoRequestCommand command) {
        try {
            if (null == command) {
                return Result.fail("参数不能为空");
            }
            command.setMerchantNo(SRC_MERCHANT_NO);
            JSONObject send = ysHttpUtil.sendBase(ServiceEnum.WX_AuthQueryByApplyNo, YsPayConstant.ENV_PRD,
                    MERCHANT_PRX, MERCHANT_PRX_PWD, ServiceEnum.WX_AuthQueryByApplyNo.getApiName(), SRC_MERCHANT_NO, command);
            return Result.ok(send);
        } catch (Exception var) {
            return Result.fail(var.getMessage());
        }
    }


    /**
     * 微信查询商户授权状态
     *
     * @param command
     * @return
     */
    @GetMapping("wxAuthState")
    public Result wxAuthState(WxAuthStateRequestCommand command) {
        try {
            if (null == command) {
                return Result.fail("参数不能为空");
            }
            command.setSrcMerchantNo(SRC_MERCHANT_NO);
            JSONObject send = ysHttpUtil.sendBase(ServiceEnum.WX_AUTHSTATE, YsPayConstant.ENV_PRD,
                    MERCHANT_PRX, MERCHANT_PRX_PWD, ServiceEnum.WX_AUTHSTATE.getApiName(), SRC_MERCHANT_NO, command);
            return Result.ok(send);
        } catch (Exception var) {
            return Result.fail(var.getMessage());
        }
    }


    /**
     * 微信撤销申请单
     *
     * @param command
     * @return
     */
    @GetMapping("wxAuthCancelApply")
    public Result wxAuthCancelApply(WxAuthCancelApplyRequestCommand command) {
        try {
            if (null == command) {
                return Result.fail("参数不能为空");
            }
            JSONObject send = ysHttpUtil.send(ServiceEnum.WX_AuthCancelApply, YsPayConstant.ENV_PRD,
                    MERCHANT_PRX, MERCHANT_PRX_PWD, ServiceEnum.WX_AuthCancelApply.getApiName(), command);
            JSONObject result = send.getJSONObject("bizResponseJson");
            return Result.ok(result);
        } catch (Exception var) {
            return Result.fail(var.getMessage());
        }
    }


    /**
     * 提交申请单 -支付宝
     * @return
     */
    @PostMapping("aliAuthSubmitApply")
    public Result aliAuthSubmitApply(@RequestBody WxAuthMesSubmitRequestCommand command){
        try {
            if (null == command) {
                return Result.fail("参数不能为空");
            }
            command.setMerchantNo(SRC_MERCHANT_NO);
            JSONObject send = ysHttpUtil.sendBase(ServiceEnum.SUBMIT_AUTHMESSAGE, YsPayConstant.ENV_PRD,
                    MERCHANT_PRX, MERCHANT_PRX_PWD, ServiceEnum.SUBMIT_AUTHMESSAGE.getApiName(), SRC_MERCHANT_NO, command);
            return Result.ok(send);
        } catch (Exception var) {
            return Result.fail(var.getMessage());
        }
    }



    /**
     * 查询申请单状态 -支付宝
     * @return
     */
    @PostMapping("aliAuthQueryByApplyNo")
    public Result aliAuthQueryByApplyNo(GetAuthMessagesByApplyNoRequestCommand command){
        try {
            if (null == command) {
                return Result.fail("参数不能为空");
            }
            command.setMerchantNo(SRC_MERCHANT_NO);
            JSONObject send = ysHttpUtil.sendBase(ServiceEnum.GET_AUTHMESSAGEBYALLPYON, YsPayConstant.ENV_PRD,
                    MERCHANT_PRX, MERCHANT_PRX_PWD, ServiceEnum.GET_AUTHMESSAGEBYALLPYON.getApiName(), SRC_MERCHANT_NO, command);
            return Result.ok(send);
        } catch (Exception var) {
            return Result.fail(var.getMessage());
        }
    }

    /**
     * 查询商户授权状态 -支付宝
     *
     * @param command
     * @return
     */
    @GetMapping("aliAuthState")
    public Result aliAuthState(GetAuthStateRequestCommand command) {
        try {
            if (null == command) {
                return Result.fail("参数不能为空");
            }
            command.setMerchantNo(SRC_MERCHANT_NO);
            JSONObject send = ysHttpUtil.sendBase(ServiceEnum.GET_AliAuthState, YsPayConstant.ENV_PRD,
                    MERCHANT_PRX, MERCHANT_PRX_PWD, ServiceEnum.GET_AliAuthState.getApiName(), SRC_MERCHANT_NO, command);
            return Result.ok(send);
        } catch (Exception var) {
            return Result.fail(var.getMessage());
        }
    }


    /**
     * 撤销申请单-支付宝
     *
     * @param command
     * @return
     */
    @GetMapping("aliAuthCancelApply")
    public Result aliAuthCancelApply (CancelAuthMessagesRequestCommand command) {
        try {
            if (null == command) {
                return Result.fail("参数不能为空");
            }
            command.setSrcMerchantNo(SRC_MERCHANT_NO);
            JSONObject send = ysHttpUtil.sendBase(ServiceEnum.CANCLE_AUTHMESSAGE, YsPayConstant.ENV_PRD,
                    MERCHANT_PRX, MERCHANT_PRX_PWD, ServiceEnum.CANCLE_AUTHMESSAGE.getApiName(), SRC_MERCHANT_NO, command);
            return Result.ok(send);
        } catch (Exception var) {
            return Result.fail(var.getMessage());
        }
    }


}